<template>
  <div class="resumeItemContainer">
    <div class="resumeItemTitle">
      <div class="resumeItemTitleFlag" v-show="!editStatus"></div>
      <span class="resumeItemTitleContent">自我评价</span>
      <span class="resumeItemTitleAddIcon" @click="handleAddClick" v-if="!resumeData"> <img :src="resumeItemAddIcon"
          class="resumeItemAddIcon">添加</span>
    </div>
    <div class="resumeItemMain">
      <div class="resumeItemDisplayList">
        <div class="resumeItemDisplayItem">
          <div class="resumeItemDisplayItemEditButtons">
            <template v-if="!editStatus">
              <span class="resumeItemDisplayItemEditButton" @click="changeEditStatusForSingle(true)" v-if="resumeData">
                <img :src="myResumeEditIcon" /> 编辑</span>
            </template>
          </div>
          <div class="displayBlock" v-if="!editStatus">
            <div class="summaryContainer">
              <div class="summary richContent" :ref="`richContent`" v-html="resumeData"></div>
              <div class="expendContainer" @click="expandContentForSingle()" v-if="showExpend">
                <el-button type="text" :icon="expendButtonText=='展开'?'el-icon-arrow-down':'el-icon-arrow-up'">
                  {{expendButtonText||"展开"}}
                </el-button>
              </div>
            </div>
          </div>
          <div class="editBlock" v-else :id="editStatus?'edittingBlock':''">
            <div class="resumeItemEdit">
              <el-form ref="form" :model="editForm" inline :rules="rules">
                <el-form-item prop="grzz" class="textAreaFormItem">
                  <el-input type="textarea" :rows="4" placeholder="请输入自我评价" v-model="editForm.grzz" :maxlength="1600"
                    show-word-limit>
                  </el-input>
                </el-form-item>
                <el-form-item>
                  <div class="submitButtons">
                    <el-button size="small" @click="handleCancel">取 消</el-button>
                    <el-button size="small" type="primary" @click="handleSave">完 成</el-button>
                  </div>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import myResumeItemsMixin from "@/mixin/myResumeItemsMixin.js";
export default {
  name: "selfDescription",
  mixins: [myResumeItemsMixin],
  props: {
    resumeData: {
      type: String,
      default: () => "",
    },
    editStatus: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      showExpend: false,
      expendButtonText: "展开",
      editForm: { grzz: "" }, //
      rules: {
        grzz: [
          { required: true, message: "请输入自我评价", trigger: "blur" },
          { max: 1600, message: "最多输入1600字", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    resumeData: {
      immediate: true,
      handler(newValue, oldValue) {
        if (!newValue) return;
        //console.log("自我评价selfDescription 基本信息更新：", newValue);
        this.editForm.grzz = newValue;
        this.isOverflowingForSingle(this, `richContent`);
      },
    },
  },
  methods: {
    async handleSave() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const finalParams = {
            op: "person_info_busi",
            func: "updatePersonDetail",
            version: "v7.8.5",
            forName: "iphone",
            person_id: this.personId,
            param: {
              person_id: this.personId,
              param: {
                personId: this.personId,
                where: `id='${this.personId}'`,
                update: [
                  {
                    columnName: "grzz",
                    columnValue: this.editForm.grzz,
                  },
                ],
              },
            },
          };
          //console.log("修改自我评价：", finalParams);
          this.resumeGeneralInterface(
            finalParams,
            () => {
              this.changeEditStatusForSingle(false);
            },
            () => {}
          );
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    handleCancel() {
      this.changeEditStatusForSingle(false);
      if (this.resumeData) {
        this.editForm.grzz = this.resumeData;
      } else {
        this.editForm.grzz = "";
      }
    },
    handleAddClick() {
      this.editForm.grzz = "";
      this.changeEditStatusForSingle(true);
    },
    handleDeletClick() {
      //console.log("点击了删除");
    },
  },
};
</script>

<style lang="scss" scoped>
.resumeItemContainer {
  display: flex;
  flex-direction: column;
  margin: 20px 0 16px;
  .resumeItemTitle {
    display: flex;
    align-items: center;
    .resumeItemTitleFlag {
      width: 4px;
      height: 19px;
      background: #0b6eff;
      border-radius: 2px;
      margin-right: 10px;
    }
    .resumeItemTitleContent {
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 20px;
      color: #333333;
      margin-right: 19px;
    }
    .resumeItemTitleAddIcon {
      display: flex;
      align-items: center;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #4880ff;
      cursor: pointer;
      .resumeItemAddIcon {
        width: 20px;
        height: 20px;
        margin-right: 8px;
      }
    }
  }
  .resumeItemMain {
    margin-top: 16px;
    .resumeItemDisplayList {
      .resumeItemDisplayItem {
        position: relative;
        margin-bottom: 16px;
        &:last-of-type {
          margin-bottom: 0px;
        }
        &:hover {
          .displayBlock {
            background: #f8f8f8;
            border-radius: 8px;
            padding: 16px 16px 16px 16px;
          }
          .resumeItemDisplayItemEditButtons {
            display: block;
          }
        }
        .resumeItemDisplayItemEditButtons {
          display: none;
          position: absolute;
          top: -20px;
          right: 0;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #4880ff;
          line-height: 18px;
          & > span {
            display: inline-flex;
            align-items: center;
            cursor: pointer;
            margin-left: 23px;
            user-select: none;
            & > img {
              width: 16px;
              height: 16px;
              margin-right: 5px;
            }
          }
        }
        .displayBlock {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #666666;
          line-height: 18px;
          text-align: left;
          font-style: normal;
          .displayInfo {
            display: flex;
            align-items: center;
          }
          .summary {
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            color: #888888;
            line-height: 21px;
            text-align: left;
            font-style: normal;
            // margin-top: 9px;
            margin-bottom: 0px;
          }
          .bold {
            font-weight: bold;
            font-size: 15px;
            color: #000000;
            line-height: 21px;
          }
          .divide {
            width: 1px;
            height: 11px;
            background: #cccfd7;
            margin: 0 12px;
          }
        }
        .editBlock {
          margin-top: 2px;
          background: #f8f8f8;
          border-radius: 8px;
          padding: 16px;
          ::v-deep .el-form-item {
            display: inline-flex;
            flex-direction: column;
            min-width: 251px;
            margin-right: 24px;
            margin-bottom: 16px;
            margin-top: 0px;
            width: 100%;
            &.textAreaFormItem {
              width: 100%;
              .el-textarea {
                textarea {
                  padding: 0;
                  border: 0;
                  background-color: transparent;
                  font-family: PingFangSC, PingFang SC;
                  font-weight: 400;
                  font-size: 14px;
                  color: #888888;
                  line-height: 21px;
                  text-align: left;
                  font-style: normal;
                }
              }
            }
            .el-form-item__label {
              height: 22px;
              font-family: PingFangSC, PingFang SC;
              font-weight: 400;
              font-size: 14px;
              color: #666660;
              line-height: 20px;
              text-align: left;
              font-style: normal;
            }
          }
          .submitButtons {
            display: flex;
            justify-content: flex-end;
            position: relative;
            top: 24px;
            right: 0;
            .el-button {
              display: flex;
              justify-content: center;
              align-items: center;
              width: 100px;
              height: 30px;
              background: #ffffff;
              border-radius: 4px;
              border: 1px solid #cdcdcd;
              font-family: PingFang-SC, PingFang-SC;
              font-weight: bold;
              font-size: 14px;
              text-align: left;
              font-style: normal;
              padding: 0;
              &.el-button--primary {
                width: 100px;
                height: 30px;
                background: #4880ff;
                border-radius: 4px;
              }
            }
          }
        }
      }
    }
  }
}

::v-deep .el-textarea .el-input__count {
  background-color: transparent;
  bottom: -33px;
}
</style>
